package io.renren.modules.admin.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.admin.entity.CourseVideoEntity;
import io.renren.modules.admin.service.CourseVideoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 视频表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-12-25 17:04:53
 */
@RestController
@RequestMapping("admin/coursevideo")
public class CourseVideoController {

    @Autowired
    private CourseVideoService courseVideoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("admin:coursevideo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = courseVideoService.queryDetailPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{courseVideoId}")
    @RequiresPermissions("admin:coursevideo:info")
    public R info(@PathVariable("courseVideoId") Integer courseVideoId){
        CourseVideoEntity courseVideo = courseVideoService.getById(courseVideoId);

        return R.ok().put("courseVideo", courseVideo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("admin:coursevideo:save")
    public R save(@RequestBody CourseVideoEntity courseVideo){
        courseVideoService.save(courseVideo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("admin:coursevideo:update")
    public R update(@RequestBody CourseVideoEntity courseVideo){
        ValidatorUtils.validateEntity(courseVideo);
        courseVideoService.updateById(courseVideo);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("admin:coursevideo:delete")
    public R delete(@RequestBody Integer[] courseVideoIds){
        courseVideoService.removeByIds(Arrays.asList(courseVideoIds));

        return R.ok();
    }

}
